// TypeScript 类型定义

// ============= 基础类型 =============

// 用户类型
export interface User {
  id: string
  username: string
  avatar_url: string
}

// 知识库类型
export interface KnowledgeBase {
  id: string
  name: string
  cover_url: string
  docs: string[]
}

export interface Document {
  id: string
  name: string
  content: string
  knowledge_id: string
  creator_id: string
}

// 文档评论类型
export interface Comment {
  id: number;           // 注意API返回的是number
  documentId: string;   // 注意API中的字段名是documentId
  content: string;
  selectedText: string;
  creatorId: string;    // 注意API中的字段名是creatorId
  timestamp: string | Date; // API返回的是字符串，可以转换为Date
}

// ============= 用户相关类型 =============

export interface LoginRequest {
  username: string
  password: string
}

export interface RegisterRequest {
  username: string
  password: string
}


export interface LoginResponse {
  token: string
  user: User
}

export interface RegisterResponse {
  user: User
}

export interface LogoutRequest {
  token: string
}

// ============= 知识库相关类型 =============


export interface CreateKnowledgeRequest {
  name: string
  coverUrl?: string
  ownerId: string
}

export interface GetKnowledgeListResponse {
  knowledge_list: {
    id: string
    name: string
    cover_url: string
    docs: {
      id: string
      name: string
    }[]
  }[]
}

export interface CreateKnowledgeResponse {
  knowledge: KnowledgeBase
}

// ============= 文档相关类型 =============

export interface CreateDocumentRequest {
  knowledgeBaseId: string
  name: string
  content: string
  creatorId: string
}

export interface CreateDocumentResponse {
  id: number
  name: string
  knowledgeBaseId: string
  creatorId: string
}

export interface UpdateDocumentRequest {
  id: number
  content: string
  lastEditorId: string
}

export interface UpdateDocumentResponse {
  id: number
  name: string
  content: string
  knowledgeBaseId: string
  lastEditorId: string
}

export interface UpdateDocumentNameRequest {
  id: number
  name: string
}

export interface UpdateDocumentNameResponse {}

export interface DeleteDocumentResponse {
  status: boolean
}

export interface GetDocumentResponse {
  id: number
  name: string
  cover_url: string
  ownerId: string
  content: string
}

export interface GetRecentDocumentResponse {
  id: number
  name: string
  accessTime: Date
}

export interface GetSharedDocumentResponse {
  id: number
  name: string
  documentId: string
  permissionType: string
}

export interface GrantPermissionRequest {
  documentId: string
  userId: string
  permissionType: string
  grantedBy: string
}

export interface GetDocCollaboratorResponse {
  userId: number
  username: string
  documentId: string
  permissionType: string
}

export interface GetDocPermissionResponse {
  id: number
  documentId: string
  userId: string
  permissionType: string
}

// ============= 文档评论相关类型 =============
export interface CreateCommentRequest {
  documentId:String
  selectedText:string
  content: string
  timestamp: Date 
  creatorId: string
}

export interface CreateCommentResponse {
  id: string
  documentId:String
  selectedText:string
  content: string
  creator_id: string
  timestamp: Date 
}

export type GetCommentListResponse = Comment[]

export interface GetSingleCommentResponse {
  id: string
  selectedText:string
  content: string
  creator_id: string
  timestamp: Date
}

export interface CommentCreatedEvent {
  commentId: string;
  selectedText: string;
  range: {
    start: number;
    end: number;
  };
}

export interface CommentMarkProps {
  commentId: string;
  commentCount?: number;
}
// ============= 文档版本控制相关类型 =============

// 创建版本请求
export interface CreateVersionRequest {
  versionName: string
  description?: string
}

// 文档版本信息
export interface DocumentVersion {
  id: number
  documentId: string
  versionNumber: number
  versionName: string
  description?: string
  createdBy: string
  createdAt: string
}

// 版本对比相关类型
export interface VersionCompareRequest {
  version1: number
  version2: number
}

export interface VersionInfo {
  versionNumber: number
  versionName: string
  description: string
  createdBy: string
  createdAt: string
}

export interface TextDiff {
  operation: 'INSERT' | 'DELETE' | 'EQUAL'
  text: string
  startIndex: number
  endIndex: number
}

export interface TextComparison {
  diffs: TextDiff[]
  unifiedDiff: string
}

export interface HtmlDiff {
  operation: 'INSERT' | 'DELETE' | 'MODIFY'
  tagName: string
  content: string
  attributes: string | null
  position: number
}

export interface HtmlComparison {
  htmlDiff: string
  structuralDiffs: HtmlDiff[]
}

export interface JsonDiff {
  operation: 'ADD' | 'REMOVE' | 'REPLACE' | 'MOVE' | 'COPY'
  path: string
  oldValue: any
  newValue: any
  description: string
}

export interface JsonComparison {
  diffs: JsonDiff[]
  summary: string
}

export interface DiffStatistics {
  totalChanges: number
  textInsertions: number
  textDeletions: number
  textModifications: number
  htmlInsertions: number
  htmlDeletions: number
  htmlModifications: number
  jsonInsertions: number
  jsonDeletions: number
  jsonModifications: number
  similarityPercentage: number
}

export interface ComparisonResult {
  textComparison: TextComparison
  htmlComparison: HtmlComparison
  jsonComparison: JsonComparison
  statistics: DiffStatistics
}

export interface DocumentVersionCompareResponse {
  documentId: string
  version1: VersionInfo
  version2: VersionInfo
  comparison: ComparisonResult
}